﻿using GodSystemBLL;
using GodSystemCommon;
using GodSystemModel;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace GodSystem
{
    public partial class FormLogin : Form
    {
        public FormLogin()
        {
            InitializeComponent();
            textBox_username.Focus();
        }

        private void button_cancel_Click(object sender, EventArgs e)
        {
            textBox_username.Text = "";
            textBox_password.Text = "";
            textBox_username.Focus();
        }

        private void button_sure_Click(object sender, EventArgs e)
        {

            string username = textBox_username.Text.Trim();
            string password = textBox_password.Text.Trim();
            if(string.IsNullOrEmpty(password) || string.IsNullOrEmpty(username))
            {
                MessageBox.Show("账号和密码不能为空","提示", MessageBoxButtons.OK,MessageBoxIcon.Warning);
                textBox_username.Text = "";
                textBox_password.Text = "";
                textBox_username.Focus();
                return;
            }

            UsersModel usersModel = new UsersModel();
            usersModel.Name = username;
            usersModel.Password = password;
            UsersBLL loginUsersBLL = new UsersBLL();
            bool flag = loginUsersBLL.checkUser(usersModel);
            if (!flag)
            {
                MessageBox.Show("账号或密码不对", "提示",MessageBoxButtons.OK,MessageBoxIcon.Error);
                return;
            }

            this.Hide();
            FormMain formMain = new FormMain();
            formMain.Show();
        }

        private void buttonCheck_Click(object sender, EventArgs e)
        {
            string version = "1.0.0.0";
            string path = Application.StartupPath;
            MessageBox.Show("路径:" + path+",版本：" + version);
            FormUpdate formUpdate = new FormUpdate();
            formUpdate.ShowDialog();
        }
    }
}
